home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.UserControl Clock
- AutoRedraw = -1 'True
- ClientHeight = 3600
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 3540
- BeginProperty Font
- Name = "Tahoma"
- Size = 8.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- PropertyPages = "Clock.ctx":0000
- ScaleHeight = 3600
- ScaleWidth = 3540
- ToolboxBitmap = "Clock.ctx":0004
- Begin VB.Timer Timer1
- Enabled = 0 'False
- Interval = 499
- Left = 2880
- Top = 360
- End
- Begin VB.Label lblNumber
- Alignment = 2 'Center
- BackStyle = 0 'Transparent
- Caption = "9"
- BeginProperty Font
- Name = "Tahoma"
- Size = 12
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Index = 3
- Left = 3000
- TabIndex = 3
- Top = 3120
- Visible = 0 'False
- Width = 495
- End
- Begin VB.Label lblNumber
- Alignment = 2 'Center
- BackStyle = 0 'Transparent
- Caption = "6"
- BeginProperty Font
- Name = "Tahoma"
- Size = 12
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Index = 2
- Left = 2640
- TabIndex = 2
- Top = 3120
- Visible = 0 'False
- Width = 495
- End
- Begin VB.Label lblNumber
- Alignment = 2 'Center
- BackStyle = 0 'Transparent
- Caption = "3"
- BeginProperty Font
- Name = "Tahoma"
- Size = 12
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Index = 1
- Left = 2280
- TabIndex = 1
- Top = 3120
- Visible = 0 'False
- Width = 495
- End
- Begin VB.Label lblNumber
- Alignment = 2 'Center
- BackStyle = 0 'Transparent
- Caption = "12"
- BeginProperty Font
- Name = "Tahoma"
- Size = 12
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Index = 0
- Left = 1920
- TabIndex = 0
- Top = 3120
- Visible = 0 'False
- Width = 495
- End
- Begin VB.Line lSecond
- BorderWidth = 2
- X1 = 1560
- X2 = 600
- Y1 = 1560
- Y2 = 2400
- End
- Begin VB.Line lMinute
- BorderWidth = 4
- X1 = 1560
- X2 = 1560
- Y1 = 240
- Y2 = 1560
- End
- Begin VB.Line lHour
- BorderWidth = 5
- X1 = 1560
- X2 = 2160
- Y1 = 1560
- Y2 = 2160
- End
- Begin VB.Shape ClockFace
- BorderWidth = 5
- Height = 2895
- Left = 120
- Shape = 2 'Oval
- Top = 120
- Width = 2895
- End
- Attribute VB_Name = "Clock"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = True
- Attribute VB_Description = "Analog Clock Object Browser"
- Option Explicit
- 'Generic Constants
- Const PI As Double = 3.14159265358979
- Const TwoPI As Double = 2 * PI
- Const HourRatio As Single = 0.55 ' Size of hour hand
- Const MinuteRatio As Single = 0.85 ' Size of minute hand
- Const SecondRatio As Single = 0.85 ' Size of second hand
- 'Property Constants
- Const m_def_Enabled As Boolean = False ' Default with clock not enabled
- Const m_def_ShowNumbers As Boolean = False ' Default with numbers not visible
- Const m_def_ShowBorder As Boolean = True ' Default with clock border visible
- Const m_def_ShowSeconds As Boolean = True ' Default with second hand visible
- Const m_def_ColorBorder As Long = &H0 ' Default with color black
- Const m_def_ColorFace As Long = &HFFFFFF ' Default with color white
- 'Private Property Variables
- Private m_Enabled As Boolean ' Clock enabled?
- Private m_ShowNumbers As Boolean ' Numbers visible?
- Private m_ShowBorder As Boolean ' Clock border visible?
- Private m_ShowSeconds As Boolean ' Second hand visible?
- Private m_ColorBorder As OLE_COLOR ' Clock border color
- Private m_ColorFace As OLE_COLOR ' Clock face color
- Private m_Picture As StdPicture ' Clock picture
- Private m_URLPicture As String ' URL address
- 'Private Generic Variables
- Private HalfX As Long ' X-direction center of control
- Private HalfY As Long ' Y-direction center of control
- Private CurrentTime As String ' Current time
- Private OldTime As String ' Old time holder
- 'Initialize Properties for User Control
- Private Sub UserControl_InitProperties()
- m_ShowNumbers = m_def_ShowNumbers
- m_ShowBorder = m_def_ShowBorder
- m_ShowSeconds = m_def_ShowSeconds
- m_ColorBorder = m_def_ColorBorder
- m_ColorFace = m_def_ColorFace
- OldTime = Format(Now, "hhmmss")
- End Sub
- Private Sub Timer1_Timer()
- CurrentTime = Format(Now, "hhmmss")
-
- ' If the time hasn't changed, don't need to update clock
- If CurrentTime = OldTime Then
- Exit Sub
- Else
- DrawHands (CurrentTime)
- OldTime = CurrentTime
- End If
- End Sub
- Private Sub UserControl_Resize()
- Timer1.Enabled = False
- ClockFace.Move ScaleWidth * 0.01, ScaleHeight * 0.01, ScaleWidth * 0.98, ScaleHeight * 0.98
- HalfX = ScaleWidth / 2
- HalfY = ScaleHeight / 2
- CurrentTime = Format(Now, "hhmmss")
- DrawHands (CurrentTime)
- If m_ShowNumbers Then PlaceNumbers
- ' Repaint picture, if needed
- UserControl_Paint
- Timer1.Enabled = m_Enabled
- End Sub
- Private Sub UserControl_Paint()
- ' Don't need to draw if picture is invalid
- If (m_Picture Is Nothing) Then Exit Sub
- With UserControl
- .PaintPicture m_Picture, _
- .ScaleX(2, vbTwips, vbHimetric), _
- .ScaleY(2, vbTwips, vbHimetric), _
- .ScaleX(.Width - 4, vbTwips, vbHimetric), _
- .ScaleY(.Height - 4, vbTwips, vbHimetric), _
- 0, _
- 0, _
- m_Picture.Width, _
- m_Picture.Height
- End With
- End Sub
- Private Sub DrawHands(MyTime As String)
- Dim cHour As Integer
- Dim cMinute As Integer
- Dim cSecond As Integer
- cHour = CInt(Mid(MyTime, 1, 2))
- cMinute = CInt(Mid(MyTime, 3, 2))
- cSecond = CInt(Mid(MyTime, 5, 2))
- ' Draw Hour Hand
- With lHour
- .X1 = HalfX
- .Y1 = HalfY
- .X2 = HalfX + GiveX((cHour Mod 12) * 5 + (Int(cMinute / 12)), HalfX, HourRatio)
- .Y2 = HalfY - GiveY((cHour Mod 12) * 5 + (Int(cMinute / 12)), HalfY, HourRatio)
- End With
- ' Draw Minute Hand
- With lMinute
- .X1 = HalfX
- .Y1 = HalfY
- .X2 = HalfX + GiveX(cMinute, HalfX, MinuteRatio)
- .Y2 = HalfY - GiveY(cMinute, HalfY, MinuteRatio)
- End With
- ' Draw Second Hand
- With lSecond
- .X1 = HalfX
- .Y1 = HalfY
- .X2 = HalfX + GiveX(cSecond, HalfX, SecondRatio)
- .Y2 = HalfY - GiveY(cSecond, HalfY, SecondRatio)
- End With
- End Sub
- Private Function GiveX(ByVal Angle As Integer, ByVal MaxX As Integer, ByVal Ratio As Single) As Integer
- GiveX = MaxX * Ratio * Sin((Angle / 60) * TwoPI)
- End Function
- Private Function GiveY(ByVal Angle As Integer, ByVal MaxY As Integer, ByVal Ratio As Single) As Integer
- GiveY = MaxY * Ratio * Cos((Angle / 60) * TwoPI)
- End Function
- Private Sub PlaceNumbers()
- Dim tHeight As Integer
- Dim tWidth As Integer
- Dim WBorder As Integer
- Dim HBorder As Integer
- ' Get largest font size that will fit in display label
- tHeight = ScaleHeight * 0.1
- WBorder = ScaleWidth * 0.035
- HBorder = ScaleHeight * 0.02
- FontSize = 1
- While TextHeight("3") < tHeight
- FontSize = FontSize + 1
- Wend
- ' Since went to > tHeight, need to subtract 1
- FontSize = FontSize - 1
- With lblNumber(0)
- .FontSize = FontSize
- .Width = TextWidth("12")
- .Height = TextHeight("12")
- .Move HalfX - (.Width / 2), HBorder
- End With
- With lblNumber(1)
- .FontSize = FontSize
- .Width = TextWidth("3")
- .Height = TextHeight("3")
- .Move ScaleWidth - .Width - WBorder, HalfY - (.Height / 2)
- End With
- With lblNumber(2)
- .FontSize = FontSize
- .Width = TextWidth("6")
- .Height = TextHeight("6")
- .Move HalfX - (.Width / 2), ScaleHeight - .Height - HBorder
- End With
- With lblNumber(3)
- .FontSize = FontSize
- .Width = TextWidth("9")
- .Height = TextHeight("9")
- .Move WBorder, HalfY - (.Height / 2)
- End With
- End Sub
- Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
- If (AsyncProp.PropertyName = "URLPicture") Then Set Picture = AsyncProp.Value
- End Sub
- Public Property Get Enabled() As Boolean
- Enabled = m_Enabled
- End Property
- Public Property Let Enabled(ByVal New_Enabled As Boolean)
- m_Enabled = New_Enabled
- Timer1.Enabled = New_Enabled
- End Property
- Public Property Get ShowNumbers() As Boolean
- ShowNumbers = m_ShowNumbers
- End Property
- Public Property Let ShowNumbers(ByVal New_ShowNumbers As Boolean)
- m_ShowNumbers = New_ShowNumbers
- lblNumber(0).Visible = New_ShowNumbers
- lblNumber(1).Visible = New_ShowNumbers
- lblNumber(2).Visible = New_ShowNumbers
- lblNumber(3).Visible = New_ShowNumbers
- UserControl_Resize
- PropertyChanged "ShowNumbers"
- End Property
- Public Property Get ShowBorder() As Boolean
- ShowBorder = m_ShowBorder
- End Property
- Public Property Let ShowBorder(ByVal New_ShowBorder As Boolean)
- m_ShowBorder = New_ShowBorder
- ClockFace.Visible = New_ShowBorder
- ' Have to repaint, since picture needs to be redrawn based on new border
- If Not m_Picture Is Nothing Then
- UserControl_Paint
- End If
- PropertyChanged "ShowBorder"
- End Property
- Public Property Get ShowSeconds() As Boolean
- ShowSeconds = m_ShowSeconds
- End Property
- Public Property Let ShowSeconds(ByVal New_ShowSeconds As Boolean)
- m_ShowSeconds = New_ShowSeconds
- lSecond.Visible = New_ShowSeconds
- PropertyChanged "ShowSeconds"
- End Property
- Public Property Get ColorBorder() As OLE_COLOR
- ColorBorder = m_ColorBorder
- End Property
- Public Property Let ColorBorder(ByVal New_ColorBorder As OLE_COLOR)
- m_ColorBorder = New_ColorBorder
- ClockFace.BorderColor = New_ColorBorder
- lHour.BorderColor = New_ColorBorder
- lMinute.BorderColor = New_ColorBorder
- lSecond.BorderColor = New_ColorBorder
- lblNumber(0).ForeColor = New_ColorBorder
- lblNumber(1).ForeColor = New_ColorBorder
- lblNumber(2).ForeColor = New_ColorBorder
- lblNumber(3).ForeColor = New_ColorBorder
- PropertyChanged "ColorBorder"
- End Property
- Public Property Get ColorFace() As OLE_COLOR
- ColorFace = m_ColorFace
- End Property
- Public Property Let ColorFace(ByVal New_ColorFace As OLE_COLOR)
- m_ColorFace = New_ColorFace
- With ClockFace
- .FillColor = New_ColorFace
- .FillStyle = 0
- .Refresh
- End With
- PropertyChanged "ColorFace"
- End Property
- Public Property Get Picture() As StdPicture
- Set Picture = m_Picture
- End Property
- Public Property Set Picture(New_Picture As StdPicture)
- Set m_Picture = New_Picture
- ColorBorder = m_def_ColorBorder
- ColorFace = m_def_ColorFace
- With ClockFace
- .FillColor = 0
- .FillStyle = 1
- .Refresh
- End With
- UserControl.Picture = m_Picture
- UserControl_Resize
- PropertyChanged "Picture"
- End Property
- Public Property Let URLPicture(Url As String)
- If (m_URLPicture <> Url) Then
- m_URLPicture = Url
- PropertyChanged "URLPicture"
-
- On Error Resume Next
-
- UserControl.AsyncRead Url, vbAsyncTypePicture, "URLPicture"
- End If
- End Property
- Public Property Get URLPicture() As String
- URLPicture = m_URLPicture
- End Property
- 'Load property values from storage
- Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
- Dim Pic As StdPicture
- Dim Url As String
- With PropBag
- m_Enabled = .ReadProperty("Enabled", m_def_Enabled)
- m_ShowNumbers = .ReadProperty("ShowNumbers", m_def_ShowNumbers)
- m_ShowBorder = .ReadProperty("ShowBorder", m_def_ShowBorder)
- m_ShowSeconds = .ReadProperty("ShowSeconds", m_def_ShowSeconds)
- m_ColorBorder = .ReadProperty("ColorBorder", m_def_ColorBorder)
- m_ColorFace = .ReadProperty("ColorFace", m_def_ColorFace)
-
- Set Pic = .ReadProperty("Picture", Nothing)
- Url = .ReadProperty("URLPicture", "")
-
- If (Url <> "") Then
- URLPicture = Url
- ElseIf Not (Pic Is Nothing) Then
- Set Picture = Pic
- End If
- End With
- End Sub
- 'Write property values to storage
- Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
- With PropBag
- .WriteProperty "Enabled", m_Enabled, m_def_Enabled
- .WriteProperty "ShowNumbers", m_ShowNumbers, m_def_ShowNumbers
- .WriteProperty "ShowBorder", m_ShowBorder, m_def_ShowBorder
- .WriteProperty "ShowSeconds", m_ShowSeconds, m_def_ShowSeconds
- .WriteProperty "ColorBorder", m_ColorBorder, m_def_ColorBorder
- .WriteProperty "ColorFace", m_ColorFace, m_def_ColorFace
- .WriteProperty "Picture", m_Picture
- .WriteProperty "URLPicture", m_URLPicture
- End With
- End Sub
-